package com.goingup.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Passengers implements List<Passenger>{
	private ArrayList<Passenger> passengers =new ArrayList<Passenger>();
	@Override
	public boolean add(Passenger e) {
		return passengers.add(e);
	}

	@Override
	public void add(int index, Passenger element) {
		passengers.add(index, element);
	}

	@Override
	public boolean addAll(Collection<? extends Passenger> c) {
		return passengers.addAll(c);
	}

	@Override
	public boolean addAll(int index, Collection<? extends Passenger> c) {
		return passengers.addAll(index, c);
	}

	@Override
	public void clear() {
		passengers.clear();
	}

	@Override
	public boolean contains(Object o) {
		return passengers.contains(o);
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		return passengers.containsAll(c);
	}

	@Override
	public Passenger get(int index) {
		return passengers.get(index);
	}

	@Override
	public int indexOf(Object o) {
		return passengers.indexOf(o);
	}

	@Override
	public boolean isEmpty() {
		return passengers.isEmpty();
	}

	@Override
	public Iterator<Passenger> iterator() {
		return passengers.iterator();
	}

	@Override
	public int lastIndexOf(Object o) {
		return passengers.lastIndexOf(o);
	}

	@Override
	public ListIterator<Passenger> listIterator() {
		return passengers.listIterator();
	}

	@Override
	public ListIterator<Passenger> listIterator(int index) {
		return passengers.listIterator(index);
	}

	@Override
	public boolean remove(Object o) {
		return passengers.remove(o);
	}

	@Override
	public Passenger remove(int index) {
		return passengers.remove(index);
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		return passengers.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		return passengers.retainAll(c);
	}

	@Override
	public Passenger set(int index, Passenger element) {
		return passengers.set(index, element);
	}

	@Override
	public int size() {
		return passengers.size();
	}

	@Override
	public List<Passenger> subList(int fromIndex, int toIndex) {
		return passengers.subList(fromIndex, toIndex);
	}

	@Override
	public Object[] toArray() {
		return passengers.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a) {
		return passengers.toArray(a);
	}

	public List<Passenger> getByDestinationFloor(Floor floor) {
		List<Passenger> disembarking = new ArrayList<Passenger>();
		for (Passenger passenger : this) {
			if (passenger.isDestinedFor(floor))
				disembarking.add(passenger);
		}
		return disembarking;
	}

	public boolean hasPassengersGettingOffAt(Floor floor) {
		return (getByDestinationFloor(floor).size()>0);
	}

	public void removePassengersGettingOffAt(Floor floor) {
		List<Passenger> disembarkingPassengers = getByDestinationFloor(floor);
		for (Passenger passenger : disembarkingPassengers) {
			passenger.disembark();
		}
	}

}
